import geo
import pandas as pd

def driving01(key, start_address, end_address):
    """驾车"""
    start = geo.geocode(key, start_address)['geocodes'][0]['location']
    end = geo.geocode(key, end_address)['geocodes'][0]['location']
    results = geo.driving(key, start, end)
    df = pd.json_normalize(results['route']['paths'][0]['steps'])
    return df


def total_driving(df):
    """总路程"""
    distance = df['distance'].to_list()
    sum_num = 0
    for i in distance:
        sum_num += int(i)
    return sum_num


def total_driving_time(df):
    """总时间"""
    duration = df['duration'].to_list()
    sum_num = 0
    for i in duration:
        sum_num += int(i)
    return sum_num // 60


def log_request(req: 'flask_request', res: str) -> None:
    """文本"""
    with open('driving.log', 'a') as log:
        print(req.form, req.remote_addr, req.user_agent, res, file=log, sep='|')

